
package com.tianyang.yukuaifu.utils;

import android.content.Context;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.common.interfaces.DialogViewListener;
import com.tianyang.yukuaifu.common.view.CommonDialogView;

/**
 * Description: 对话框
 * Created by 薛勇军 on 2018/6/8.
 */
public class DialogUtil {

    public static DialogUtil instance = null;

    public DialogViewListener dialogViewListener;

    public static DialogUtil getInstance() {
        synchronized (DialogUtil.class) {
            if (instance == null) {
                instance = new DialogUtil();
            }
        }
        return instance;
    }

    /**
     * 不带标题一个按钮,不带回调
     * 
     * @param message
     */
    public void dialogNoTitleOneBtn(Context context, String message) {
        CommonDialogView dialog = new CommonDialogView(context, false, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {

                    }

                    @Override
                    public void doCancle() {

                    }
                });
        dialog.confirm.setText(context.getString(R.string.ok));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 带标题一个按钮,不带回调
     * 
     * @param message
     */
    public void dialogExistTitleOneBtn(Context context, String title, String message) {
        if (context == null){
            return;
        }
        CommonDialogView dialog = new CommonDialogView(context, false, title, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {

                    }

                    @Override
                    public void doCancle() {

                    }
                });
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 不带标题一个按钮,带回调
     *
     * @param message
     */
    public void dialogNoTitleOneBtnHaveCallBack(Context context, String message,
                                                DialogViewListener listener) {
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, false, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(context.getString(R.string.ok));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 不带标题一个按钮,带回调 按钮名字是关闭
     * @param context
     * @param message
     * @param listener
     */
    public void dialogNoTitleOneBtnHaveCallBacks(Context context, String message,
                                                 DialogViewListener listener) {
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, false, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(context.getString(R.string.close));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 带标题一个按钮,带回调
     *
     * @param message
     */
    public void dialogExistTitleOneBtnHaveCallBack(Context context, String title, String message,
                                                   DialogViewListener listener) {
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, false, title, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(context.getString(R.string.ok));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 不带标题两个按钮,带回调
     * 
     * @param btnLeftContent 取消
     * @param btnRightContent 确定
     * @param message
     */
    public void dialogNoTitletTwoBtnHaveCallBack(Context context, String message,
                                                 String btnLeftContent, String btnRightContent, DialogViewListener listener) {
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, true, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(btnRightContent);
        dialog.cancel.setText(btnLeftContent);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 带标题两个按钮,带回调
     *
     * @param btnLeftContent 取消
     * @param btnRightContent 确定
     * @param message
     */
    public void dialogExistTitleTwoBtnHaveCallBack(Context context, String title, String message,
                                                   String btnLeftContent, String btnRightContent, DialogViewListener listener) {
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, true, title, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {

                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }

                    }
                });
        dialog.confirm.setText(btnRightContent);
        dialog.cancel.setText(btnLeftContent);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }



    /**
     * 显示两个按钮的dialog提示框
     * @param context 上下文
     * @param title 标题
     * @param message 内容
     * @param btnLeftContent 左边文本
     * @param btnRightContent 右边文本
     * @param listener 回调监听
     */
    public void showDialogPromptByTwoBtnHaveCallBack(Context context, String title, String message,
                                                     String btnLeftContent, String btnRightContent, DialogViewListener listener){
        this.dialogViewListener = listener;
        CommonDialogView dialog = new CommonDialogView(context, true, title, message,
                new CommonDialogView.DialogViews_ask() {
                    @Override
                    public void doOk() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnRightConfirm();
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (dialogViewListener != null) {
                            dialogViewListener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(btnRightContent);
        dialog.cancel.setText(btnLeftContent);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 带标题,带输入框,两个按钮,带回调
     *
     * @param btnLeftContent 取消
     * @param btnRightContent 确定
     * @param message
     * @param hintContent 输入框提示文字
     */
    public void dialogExistInputTowBtnHaveCallBack(Context context, boolean passwordInput, String title, String message,
                                                   String hintContent, String btnLeftContent, String btnRightContent,
                                                   final DialogViewListener.DialogViewListenerImpl listener) {
        this.dialogViewListener = listener;
        final CommonDialogView dialog = new CommonDialogView(context,passwordInput, true, title, message, true,
                hintContent, new CommonDialogView.DialogViews_ask.DialogViews_askImpl() {
                    @Override
                    public void doOk(String text) {
                        if (listener != null) {
                            listener.btnRightConfirm(text);
                        }
                    }

                    @Override
                    public void doCancle() {
                        if (listener != null) {
                            listener.btnLeftCancel();
                        }
                    }
                });
        dialog.confirm.setText(btnRightContent);
        dialog.cancel.setText(btnLeftContent);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

}
